package studio.raptor.ddal.dashboard.log.bo;

import lombok.Getter;
import lombok.Setter;
import studio.raptor.ddal.core.log.bo.SqlProcessLogData;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by liujy on 2018/1/4.
 */
@Getter
@Setter
@Entity
@Table(name = "log_sql_process")
public class SqlProcessLogExtendData  implements Serializable,Cloneable{

    @Id
    @Column(name = "trace_id")
    private String traceId;
    @Column(name = "start_time")
    private String startTime;
    @Column(name = "end_time")
    private String endTime;
    @Column(name = "process_time")
    private long processTime;
    @Column(name = "sql_type")
    private String sqlType;
    @Column(name = "shards")
    private String shardsStr;
    @Column(name = "host_ip")
    private String hostIp;
    @Column(name = "tables")
    private String tablesStr;
    @Column(name = "originsql") //sql为Mysql的关键字
    private String sql;
    @Column(name = "parameters")
    private String parametersStr;
    private String plan;
    @Column(name = "dbuser")
    private String dbUsersStr;
    @Column(name = "datasource")
    private String dataSourcesStr;
    @Column(name = "issucess")
    private String sucess;
    @Column(name = "errormsg")
    private String errorMsg="";
    @Column(name = "create_time")
    private Date createTime;
    @Column(name = "accept_time")
    private Date acceptTime;
    @Column(name = "appname")
    private String appName;
    @Column(name = "finalsql")
    private String finalSqlStr;

    public void clone(SqlProcessLogData sqlProcessLogData){
        this.traceId=sqlProcessLogData.getTraceId();
        this.startTime=sqlProcessLogData.getStartTime();
        this.endTime=sqlProcessLogData.getEndTime();
        this.processTime=sqlProcessLogData.getProcessTime();
        this.sqlType=sqlProcessLogData.getSqlType();
        this.shardsStr=sqlProcessLogData.getShards()+"";
        this.hostIp=sqlProcessLogData.getHostIp();
        this.tablesStr=sqlProcessLogData.getTables()+"";
        this.sql=sqlProcessLogData.getSql();
        this.parametersStr=sqlProcessLogData.getParameters()+"";
        this.plan=sqlProcessLogData.getPlan();
        this.dbUsersStr=sqlProcessLogData.getDbUsers()+"";
        this.dataSourcesStr=sqlProcessLogData.getDataSources()+"";
        this.sucess=sqlProcessLogData.getSucessStr();
        this.errorMsg=sqlProcessLogData.getErrorMsg();
        this.acceptTime=sqlProcessLogData.getAcceptTime();
        this.finalSqlStr=sqlProcessLogData.getFinalSqlList()+"";
    }
}
